Previous Up Next

Syntax for Cool Objects

Every Cool value is an object. Objects contain a list of named attributes, a bit like records in C. In addition, each object belongs to a class. We use the following syntax for values in Cool:

\[ v = X(a_{1} = l_{1}, a_{2} = l_{2}, \dots , a_{n} = l_{n}) \]

Read the syntax as follows: The value \( v\) is a member of class \(X\) containing the attributes \(a_1, \ldots, a_n\) whose locations are \(l_1, \ldots, l_n\). Note that the attributes have an associated location. Intuitively this means that there is some space in memory reserved for each attribute. The value \( v\) has dynamic type \(X\).

For base objects of Cool (i.e., \(\tt Int\)s, \(\tt String\)s, and \(\tt Bool\)s) we use a special case of the above syntax. Base objects have a class name, but their attributes are not like attributes of normal classes, because they cannot be modified. Therefore, we describe base objects using the following syntax:

\[ \begin{array}{l} Int(5) \\ Bool(true) \\ String(4,{\tt"Cool"}) \end{array} \]

For \(\tt Int\)s and \(\tt Bool\)s, the meaning is obvious. \(\tt String\)s contain two parts, the length and the actual sequence of ASCII characters.

Previous Up Next